<?php

/**
 * @author aisyah
 * @copyright 2012
 */

class Tanggal{
    
    var $tgl_awal;
    var $tgl;
    var $bulan;
    var $tahun;
    var $bulan_indo;
    var $tgl_indo;
    
    public function __construct($tgl=null){
        
        if(!is_null($tgl)) {
            $this->tgl_awal = $tgl;
        }
        
        
    }
    
    public function set_tgl($tgl) {
        
        $this->tgl_awal = $tgl;
        
    }
    
    function _pisah_tgl($tgl){
        
        $temp = array();
        
        $temp = explode("-", $tgl);
        
        $this->tahun = $temp[0];        
        $this->bulan = $temp[1];
        $this->bulan = $this->_cek_bulan($this->bulan);
        $this->tgl = $temp[2];        
        
    }
    
    function _cek_bulan(){
        
        $bulan = $this->bulan;
        
        $temp = substr($bulan, 0, 1);
        
        if($temp=="0"){
            
            $bulan = substr($bulan, 1, 1);
            
        }
        
        return $bulan;
        
    }
    
    function _tgl_indo(){
        
        $bln_indo = array(1=>"Januari", 
                    2=>"Februari",
                    3=>"Maret",
                    4=>"April",
                    5=>"Mei",
                    6=>"Juni",
                    7=>"Juli",
                    8=>"Agustus",
                    9=>"September",
                    10=>"Oktober",
                    11=>"November",
                    12=>"Desember");
            
            $this->_pisah_tgl($this->tgl_awal);                   
        
            if(array_key_exists($this->bulan, $bln_indo)) {
                
                $this->bulan_indo = $bln_indo[$this->bulan];                
                
            }
            
            $this->tgl_indo = $this->tgl." ".$this->bulan_indo." ".$this->tahun;
        
    }
    
    public function get_tgl_indo(){
        
        //$this->_pisah_tgl($this->tgl_awal);
        $this->_tgl_indo();        
        //$tgl_indo = $this->tgl." ".$this->bulan_indo." ".$this->tahun;
        return $this->tgl_indo;
        
    }
    
}

/*
* test
* dan cara pemakaian
*
*
//$tgl = new Tanggal("2012-10-11");
$tgl = new Tanggal();

//$tgl_indo = $tgl->get_tgl_indo();

//print_r($tgl_indo."</br>");

$tgl->set_tgl("2013-05-3");

$tgl_indo = $tgl->get_tgl_indo();

print_r($tgl_indo."</br>");

$tgl->set_tgl("2020-07-29");

$tgl_indo = $tgl->get_tgl_indo();

print_r($tgl_indo."</br>");

**/